import { ref } from 'vue'

export default function () {
  const input = ref<HTMLInputElement | null>(null)
  function uploadFile() {
    input.value?.click()
  }
  // 文件解析
  function readerFile(e: HTMLInputElement) {
    const files = e.files
    if (files) {
      const reader = new FileReader()
      reader.readAsArrayBuffer(files[0])
      reader.onload = () => {
        const file = reader.result
        // 发送到服务器
        console.log(file)
      }
    }
  }
  return {
    input,
    uploadFile,
    readerFile
  }
}
